/**
 * Created by chengming on 18/5/24.
 * version 1.0
 */

const BaseHrefAdapter = require('../base/BaseHrefAdapter');

module.exports = class KrFlash extends BaseHrefAdapter{

	parseHtml(html, linkRule){

		var extractJson = html.match(/<script>var props=(.+),locationnal=/);
		var extractObj = JSON.parse(extractJson[1]);

		if(extractObj){
			var newsflash = extractObj['newsflashList|newsflash'];
			let contents = [];
			let rangeText = '';
			for(var i = 0;  i < newsflash.length; i++ ){

				let title = '【' + newsflash[i].title + '】' + newsflash[i].description;
				let href = newsflash[i].news_url;

				contents.push({
					title:title,
					href:href
				});
				rangeText +=title+href;
			}

			return {
				rangeText: rangeText,
				contents: contents
			};
		}
	}

}